#pragma once

#include "ui.h"
#include "ui_base.h"

_SSL_BEGIN
_SSUIL_BEGIN

#pragma warning(push)
#pragma warning(disable:4275)
#pragma warning(disable:4251)
#pragma warning(disable:4250)

class SSUI_CLASS UIBuilder :
	public IUIBuilderInterface,
	virtual public ref_counted_base
{
public:
	UIBuilder();
	virtual ~UIBuilder();

	// IUIBuilderInterface
public:
	virtual bool AppendBuildCallback(
		IUIBuilderCallbackInterface *cb
		);
	virtual bool RemoveBuildCallback(IUIBuilderCallbackInterface *cb);
	virtual void ClearBuildCallback();

	virtual bool Build(
		ss_in_ IUIDiskFilesManagerInterface *disk_man,
		ss_in_ const tchar* ui_xml_file,
		ss_in_ const tchar* xml_window_node_name,
		ss_in_ bool load_global_resource,
		ss_in_ IUIWindowBgCanvasInterface *bg_canvas_,
		ss_in_ IUIResourceRenderInterface *res_ren,
		ss_out_ scoped_ref_ptr<IUIWindow> &ui_win,
		ss_in_ HWND parent_win_h = NULL,
		ss_in_ UINT id = 0,
		ss_in_ HINSTANCE inst = NULL
		);

	virtual bool BuildControl(
		ss_in_ IUIXMLDocumentInterface *xml_document,
		ss_in_ UIXmlNode node,
		ss_out_ scoped_ref_ptr<IUIControlInterface> &control
		);
	virtual bool BuildControl(
		ss_in_ const tstring &ui_description,
		ss_out_ scoped_ref_ptr<IUIControlInterface> &control
		);
	virtual bool LoadXml(
		ss_in_ const tchar *xml_file,
		ss_out_ scoped_ref_ptr<IUIXMLDocumentInterface> &xml_doc
		);

	virtual bool BuildWindow(
		ss_in_ IUIXMLDocumentInterface *xml_document,
		ss_in_ const tchar* xml_window_node_name,
		ss_in_ bool load_global_resource,
		ss_in_ IUIWindowBgCanvasInterface *bg_canvas,
		ss_in_ IUIResourceRenderInterface *res_ren,
		ss_out_ scoped_ref_ptr<IUIWindow> &ui_win,
		ss_in_ HWND parent_win_h,
		ss_in_ UINT id,
		ss_in_ HINSTANCE inst
		);

	//
protected:
	bool BuildGlobalRes(
		ss_in_ IUIXMLDocumentInterface *xml_document,
		ss_in_ UIXmlNode node,
		ss_inout_ IUIResourceRenderInterface *res_ren);

	bool BuildUIWindow(
		ss_in_ IUIXMLDocumentInterface *xml_document,
		ss_in_ UIXmlNode node,
		ss_in_ IUIWindowBgCanvasInterface *bg_canvas_,
		ss_in_ IUIResourceRenderInterface *res_ren,
		ss_in_ IUIDiskFilesManagerInterface *disk_man,
		ss_out_ scoped_ref_ptr<IUIWindow> &ui_win,
		ss_in_ HWND parent_win_h,
		ss_in_ UINT id,
		ss_in_ HINSTANCE inst
		);

	//
protected:
	IUIBuilderCallbackInterfaceAutoPtrs build_callbacks_;
	scoped_ref_ptr<IUIDiskFilesManagerInterface> disk_files_manager_;
};
#pragma warning(pop)

_SSUIL_END
_SSL_END
